import Vue from 'vue'
import Vuex from 'vuex'
import VuexPersistence from "vuex-persist";
import homegoods from './modules/homegoods'

import meaulist from './meau/meaumodule'
import user from './user/usermodule'
import tabbar from './tabbar/tabbarmodule'
import axios from 'axios'
Vue.use(Vuex)

const vuexLocal = new VuexPersistence({
  storage: window.sessionStorage //数据持久化,避免刷新数据消失
});
export default new Vuex.Store({
  state: {
		datalist: [],
    list: [],
    ensuresrc: '',
    discountsrc: '',
    assemblysrc: [],
    newarrivalsrc: [],
    inspiredsrc: [],
    collection: [],
    collectionsrc: {},
    living: {},
    alldatalist: [],
    alldata: {
      first: [],
      second: [],
      third: [],
      fourth: [],
      fifth: [],
      sixth: []
    }
  },
  mutations: {
		setDataList(state, data) {
			state.datalist = data
		},
    pushdata (state, data) {
      state.list = data[0].moduleContent.banners
      state.ensuresrc = data[1].moduleContent.bannerImgSrc
      state.discountsrc = data[2].moduleContent.bannerImgSrc
      state.assemblysrc = data[3].moduleContent.banners
      state.assemblysrc.push(...data[4].moduleContent.banners)
      state.newarrivalsrc = data[5].moduleContent.banners
      state.inspired = data[6].moduleContent.bannerImgSrc
      state.inspiredsrc.push(data[7].moduleContent)
    },
    pushtwodata (state, data) {
      state.inspiredsrc.push(data[0].moduleContent)
      state.collection = data[1].moduleContent.bannerImgSrc
      state.collectionsrc.img = data[2].moduleContent.banners[0].bannerImgSrc
      state.collectionsrc.imgsrc = data[2].moduleContent.products
      state.living.img = data[3].moduleContent.banners[0].bannerImgSrc
      state.living.imgsrc = data[3].moduleContent.products
      state.alldata.first.push(...data.slice(5))
    },
    pushthreedata (state, data) {
      state.alldata.first.push(...data.slice(0, 4))
      state.alldatalist.push(state.alldata.first)
      state.alldata.second.push(...data.slice(4))
    },
    pushfourdata (state, data) {
      state.alldata.second.push(...data.slice(0, 3))
      state.alldatalist.push(state.alldata.second)
      state.alldata.third.push(...data.slice(3))
    },
    pushfivedata (state, data) {
      state.alldata.third.push(...data.slice(0, 2))
      state.alldatalist.push(state.alldata.third)
      state.alldata.fourth.push(...data.slice(2))
      state.alldatalist.push(state.alldata.fourth)
    },
    pushsixdata (state, data) {
      state.alldata.fifth.push(...data.slice(0, 7))
      state.alldatalist.push(state.alldata.fifth)
      state.alldata.sixth.push(...data.slice(7))
    },
    pushsevendata (state, data) {
      state.alldata.sixth.push(...data.slice(0, 6))
      state.alldatalist.push(state.alldata.sixth)
    }
  },
  actions: {
    getdata (store) {
      axios({
        url: '/v2/page?pageId=1&tabId=1&currentPage=1&pageSize=8',
        method: 'get'
      }).then(res => {
        store.commit('pushdata', res.data.data.modules)
      })
    },
    twogetdata (store) {
      axios({
        url: '/v2/page?pageId=1&tabId=1&currentPage=2&pageSize=8',
        method: 'get'
      }).then(res => {
        store.commit('pushtwodata', res.data.data.modules)
      })
    },
    threegetdata (store) {
      axios({
        url: '/v2/page?pageId=1&tabId=1&currentPage=3&pageSize=8',
        method: 'get'
      }).then(res => {
        store.commit('pushthreedata', res.data.data.modules)
      })
    },
    fourgetdata (store) {
      axios({
        url: '/v2/page?pageId=1&tabId=1&currentPage=4&pageSize=8',
        method: 'get'
      }).then(res => {
        store.commit('pushfourdata', res.data.data.modules)
      })
    },
    fivegetdata (store) {
      axios({
        url: '/v2/page?pageId=1&tabId=1&currentPage=5&pageSize=8',
        method: 'get'
      }).then(res => {
        store.commit('pushfivedata', res.data.data.modules)
      })
    },
    sixgetdata (store) {
      axios({
        url: '/v2/page?pageId=1&tabId=1&currentPage=6&pageSize=8',
        method: 'get'
      }).then(res => {
        store.commit('pushsixdata', res.data.data.modules)
      })
    },
    sevengetdata (store) {
      axios({
        url: '/v2/page?pageId=1&tabId=1&currentPage=7&pageSize=8&',
        method: 'get'
      }).then(res => {
        store.commit('pushsevendata', res.data.data.modules)
      })
    }
  },
	modules: {
		meaulist,
		user,
		tabbar,
		homegoods
	},
	plugins: [vuexLocal.plugin]
})
